from django.http import HttpResponse
from django.urls import reverse, resolve


# Create your views here.
def index(request):
    # reverse("user:user_index")--- 反向解析
    # user:user_index --- 命名空间:路由名称
    route_url = reverse("userinfo:user_index")
    print("reverse反向解析得到路由地址1：" + route_url)
    result = resolve(route_url)
    print("resolve通过路由地址得到路由信息2：" + str(result))
    return HttpResponse("⽤户信息")


def list(request, year, month, day):
    kwargs = {'year': year - 1, 'month': month + 1, 'day': day}
    # 使⽤reverse函数和kwargs参数反向解析出订单列表⻚⾯的URL
    route_url = reverse('userinfo:list', kwargs=kwargs)
    print("reverse反向解析得到路由地址：" + route_url)
    # 通过resolve函数正向解析URL，以验证反向解析的结果
    result = resolve(route_url)
    print("resolve通过路由地址得到路由信息：" + str(result))
    print("resolve通过路由地址得到路由信息：" + str(result.namespaces))
    return HttpResponse("⽤户列表")
